#include "XYSeries.h"
#include "Image.h"
#include <QSlider>

XYSeries::XYSeries():SeriesBase()
{
	vt = SeriesBase::XY;
}

XYSeries::~XYSeries()
{

}

void XYSeries::nextFrame()
{
	++curXYFrame;
	if (curXYFrame >= dicomsSize)
		curXYFrame = 0;
	slider->setValue(curXYFrame);
}

void XYSeries::prevFrame()
{
	--curXYFrame;
	if (curXYFrame < 0)
		curXYFrame = dicomsSize - 1;
	slider->setValue(curXYFrame);
}

void XYSeries::gotoFrame(int index)
{
	if (index < 0)
		curXYFrame = 0;
	else if (curXYFrame >= dicomsSize)
		curXYFrame = dicomsSize - 1;
	else curXYFrame = index;
	slider->setValue(curXYFrame);
}

bool XYSeries::getPixmap(QPixmap & pixmap)
{
	if (dicoms.isEmpty())
		return false;
	Image *image = dicoms.values().at(curXYFrame);
	if (winWidth < 1) winWidth = 1;
	image->setWindow(winCenter, winWidth);

	return image->getPixmap(pixmap);
}

int XYSeries::getCurFrame()
{
	return curXYFrame;
}

int XYSeries::getFrameCount()
{
	return dicoms.size();
}

bool XYSeries::getRectSize(int & x_width, int & y_height)
{
	if (isNormal())
	{
		x_width = imageWidth;
		y_height = imageHeight;
		return true;
	}
	return false;
}

bool XYSeries::getPixSpacing(double & xs, double & ys)
{
	if (isNormal())
	{
		double zs;
		return dicoms.values().first()->getPixSpacing(xs, ys, zs);
	}
	return false;
}

QString XYSeries::getPixelValue(int x, int y)
{
	if (isNormal())
	{
		return dicoms.values().at(curXYFrame)->getPixInfo(x,y);
	}
	return "";
}
